﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter06
{
    partial class Program
    {
        internal static void Begin(Action action, bool active = false)
        {
            if (active)
            {
                Console.WriteLine("开始演示：");
                action();
                Console.WriteLine("演示完毕：");
                Console.ReadLine();
            }
        }

        internal static void C01()
        {
            {
                Console.WriteLine();
                object o = new object();
                o.GetHashCode();
                o.GetType();
            }
            {
                Employee e = null;
                e.GenProgressReport();
            }
        }

        private sealed class SomeType
        {
            private class SomeNestedType { }
            private const int SomeConstant = 1;
            private readonly int SomeReadOnlyField = 2;
            private static int SomeReadWriteField = 3;

            static SomeType() { }

            internal SomeType() { }

            internal SomeType(int x) { }

            private string InstanceMethod()
            {
                Console.WriteLine(SomeConstant);
                Console.WriteLine(SomeReadOnlyField);
                Console.WriteLine(SomeReadWriteField);
                SomeEvent(this, EventArgs.Empty);
                return null;
            }

            internal static void MainSmoe() { }

            internal int SomeProp { get { return 0; } set { } }

            internal int this[string s] { get { return 0; } set { } }

            internal event EventHandler SomeEvent;
        }

        private static class AStaticClass
        {
            internal static void AStaticMethod()
            {
                AStaticEvent(null, EventArgs.Empty);
            }

            internal static string AStaticProperty { get { return aStaticProperty; } set { aStaticProperty = value; } }

            private static string aStaticProperty;

            internal static event EventHandler AStaticEvent;
        }

        private class Employee
        {
            internal int GetYearsEmployed() { return 0; }

            internal virtual string GenProgressReport() { return null; }

            internal static Employee Lookup(string name) { return null; }
        }

        private class SomeClass
        {
            public override string ToString()
            {
                return base.ToString();
            }
        }

        private class Set
        {
            private int length = 0;

            internal int Find(object value)
            {
                return Find(value, 0, length);
            }

            internal int Find(object value, int startIndex, int endIndex)
            {
                return 0;
            }
        }

        internal static void C02()
        {
            Point p = new Point(3, 4);
            Console.WriteLine(p);
        }

        private sealed class Point
        {
            private int x, y;

            internal Point(int x, int y)
            {
                this.x = x;
                this.y = y;
            }

            public override string ToString()
            {
                return string.Format("{0}, {1}", x, y);
            }
        }

        internal static void C03()
        {
            BetterPhone phone = new BetterPhone();
            phone.Dial();
        }

        private class SimulatedClosedClass : Object
        {
            public override bool Equals(object obj)
            {
                return base.Equals(obj);
            }

            public override int GetHashCode()
            {
                return base.GetHashCode();
            }

            public override string ToString()
            {
                return base.ToString();
            }
        }

        private class Phone
        {
            internal void Dial()
            {
                Console.WriteLine("Phone Dial");
                EstablishConnection();
            }

            protected virtual void EstablishConnection()
            {
                Console.WriteLine("Phone.EstablishConnection");
            }
        }

        private class BetterPhone : Phone
        {
            new internal void Dial()
            {
                Console.WriteLine("BetterPhone.Dial");
                EstablishConnection();
                base.Dial();
            }

            protected override void EstablishConnection()
            {
                Console.WriteLine("BetterPhone.EstablishConnection");
            }
        }
    }
}
